package ossFileinfo

import (
	"common/comOss"
	"context"
	"fmt"

	"file/internal/svc"
	"file/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OssGetInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOssGetInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OssGetInfoLogic {
	return &OssGetInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OssGetInfoLogic) OssGetInfo() (resp *types.OssResponse, err error) {
	// todo: add your logic here and delete this line
	user := l.ctx.Value("token")
	fmt.Println(user)
	response, err := comOss.GetOssResponse(l.svcCtx.Config.OSS)
	if err != nil {
		return nil, err
	}
	return &types.OssResponse{
		RequestId: response.RequestId,
		Point:     l.svcCtx.Config.OSS.Pint,
		Address:   l.svcCtx.Config.OSS.Address,
		Bucket:    l.svcCtx.Config.OSS.Bucket,
		AssumedRoleUser: types.AssumedRoleUser{
			Arn:           response.AssumedRoleUser.Arn,
			AssumedRoleId: response.AssumedRoleUser.AssumedRoleId,
		},
		Credentials: types.Credentials{
			AccessKeyId:     response.Credentials.AccessKeyId,
			AccessKeySecret: response.Credentials.AccessKeySecret,
			Expiration:      response.Credentials.Expiration,
			SecurityToken:   response.Credentials.SecurityToken,
		},
	}, nil
}
